package logic

import (
	"context"
	"fmt"
	"srv/model/redis"

	"srv/cart"
	"srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCartLogic {
	return &ListCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListCartLogic) ListCart(in *cart.ListCartRequest) (*cart.ListCartResponse, error) {
	// todo: add your logic here and delete this line
	listCart, err := redis.ListCart(in.UserId)
	if err != nil {
		logx.Error("列表展示失败")
		return nil, fmt.Errorf("列表展示失败")

	}
	return &cart.ListCartResponse{List: listCart}, nil
}
